﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text;
using DosTexPrj.Core.Models;

namespace DosTexPrj.UI.WinForm.Commons
{
    public static class Printing
    {
        public static void AddTitleToPdf(Document pdfFile, string title, Font fBig)
        {
            PdfPTable table = new PdfPTable(1);
            PdfPCell cell = new PdfPCell(new Phrase(title, fBig));
            cell.HorizontalAlignment = 1;
            cell.Border = Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.NO_BORDER;
            table.AddCell(cell);
            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddSignaturesToPdf(Document pdfFile, Font fBold, string text1, string text2)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 10f, 10f };
            table.SetTotalWidth(widths);

            // row 1
            //col 1
            PdfPCell cell = new PdfPCell(new Phrase(text1, fBold));
            cell.HorizontalAlignment = 1;
            cell.Border = Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.NO_BORDER;
            cell.PaddingTop = 5f;
            table.AddCell(cell);
            // col 2
            cell = new PdfPCell(new Phrase(text2, fBold));
            cell.HorizontalAlignment = 1;
            cell.Border = Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.NO_BORDER;
            cell.PaddingTop = 5f;
            table.AddCell(cell);
            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }
    }

    public static class CommonPrinting
    {
        public static void DrawGridHeaderItem(PdfPTable table, string text, Font fStyle)
        {
            PdfPCell cell = new PdfPCell(new Phrase(text, fStyle));
            cell.HorizontalAlignment = 1;
            cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
            cell.BackgroundColor = BaseColor.LIGHT_GRAY;
            cell.PaddingBottom = 2f;
            table.AddCell(cell);
        }

        public static void DrawGridDataItem(PdfPTable table, string text, Font fStyle, int textAlign)
        {
            PdfPCell cell = new PdfPCell(new Phrase(text, fStyle));
            cell.HorizontalAlignment = textAlign;
            cell.Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
            cell.PaddingBottom = 2f;
            table.AddCell(cell);
        }

        public static void DrawNormalItemInfo(PdfPTable table, string text, Font fStyle, int textAlign, int colspan, float paddingBottom)
        {
            PdfPCell cell = new PdfPCell(new Phrase(text, fStyle));
            cell.HorizontalAlignment = textAlign;
            if (colspan > 0)
            {
                cell.Colspan = colspan;
            }
            cell.Border = Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.NO_BORDER | Rectangle.NO_BORDER;
            cell.PaddingBottom = paddingBottom;
            table.AddCell(cell);
        }
    }

    #region -- Order Printing --

    public static class OrderPrinting
    {
        public static void AddOrderInfoToPdf(Document pdfFile, Order order, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Order Informations", fBold, 0, 2, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Order No.", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Id.ToString(), fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Order Date", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.OrderDate.ToShortDateString(), fBold, 0, 0, 2f);
            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Method Of Payment", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.PaymentMethod.PaymentMethodName, fBold, 0, 0, 2f);
            // row 4
            CommonPrinting.DrawNormalItemInfo(table, "Method Of Delivery", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.DeliveryMethod.DeliveryMethodName, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddCustomerInfoToPdf(Document pdfFile, Customer customer, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Customer Informations", fBold, 0, 2, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Name", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, customer.CustomerName, fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Address", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, customer.Address, fBold, 0, 0, 2f);
            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Phone", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, customer.PhoneNumber, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddConditionInfoToPdf(Document pdfFile, Order order, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Order Conditions", fBold, 0, 2, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Dilivery Date", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.DeliveryDate.ToShortDateString(), fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Payment Condition", fNormal, 0, 0, 2f);
            string dataTemp = string.Empty;
            if (!order.IsDeliveredBefore && order.NumberOfDateExtensionDelivery == 0)
            {
                dataTemp = string.Empty;
            }
            else if (!order.IsDeliveredBefore && order.NumberOfDateExtensionDelivery != 0)
            {
                dataTemp = "After delivery " + order.NumberOfDateExtensionDelivery.ToString() + " day(s)";
            }
            else if (order.IsDeliveredBefore)
            {
                dataTemp = "Before delivery";
            }
            CommonPrinting.DrawNormalItemInfo(table, dataTemp, fBold, 0, 0, 2f);

            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Freight", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Freight, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddOrderDetailToPdf(Document pdfFile, IList<OrderDetail> details, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(10);
            float[] widths = { 5f, 10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Order Detail Informations", fBold, 0, 10, 2f);

            // row  header

            // col 1
            CommonPrinting.DrawGridHeaderItem(table, "No.", fBold);
            // col 2
            CommonPrinting.DrawGridHeaderItem(table, "Fabric Type", fBold);
            // col 3
            CommonPrinting.DrawGridHeaderItem(table, "Colour", fBold);
            // col 4
            CommonPrinting.DrawGridHeaderItem(table, "Composition", fBold);
            // col 5
            CommonPrinting.DrawGridHeaderItem(table, "Qtt.(Mt)", fBold);
            // col 6
            CommonPrinting.DrawGridHeaderItem(table, "Qtt.(Kg)", fBold);
            // col 7
            CommonPrinting.DrawGridHeaderItem(table, "Cuttable Width", fBold);
            // col 8
            CommonPrinting.DrawGridHeaderItem(table, "Weight", fBold);
            // col 9
            CommonPrinting.DrawGridHeaderItem(table, "Yield", fBold);
            // col 10
            CommonPrinting.DrawGridHeaderItem(table, "Price", fBold);

            // row data
            if (details != null && details.Count > 0)
            {
                for (int i = 0; i < details.Count; i++)
                {
                    // col 1
                    CommonPrinting.DrawGridDataItem(table, i + 1 + "", fNormal, 1);
                    // col 2
                    CommonPrinting.DrawGridDataItem(table, details[i].FabricType.FabricTypeName, fNormal, 0);
                    // col 3
                    CommonPrinting.DrawGridDataItem(table, details[i].Color, fNormal, 0);
                    // col 4
                    CommonPrinting.DrawGridDataItem(table, details[i].Composition.CompostionName, fNormal, 0);
                    // col 5
                    CommonPrinting.DrawGridDataItem(table, details[i].MtQuantity.ToString(), fNormal, 0);
                    // col 6
                    CommonPrinting.DrawGridDataItem(table, details[i].KgQuantity.ToString(), fNormal, 0);
                    // col 7
                    CommonPrinting.DrawGridDataItem(table, details[i].CuttableWidth.ToString(), fNormal, 0);
                    // col 8
                    CommonPrinting.DrawGridDataItem(table, details[i].Weight.ToString(), fNormal, 0);
                    // col 9
                    double yield = (1000f / details[i].CuttableWidth / details[i].Weight * 100) - (((1000f / details[i].CuttableWidth / details[i].Weight * 100) / 100) * 5);
                    CommonPrinting.DrawGridDataItem(table, Math.Round(yield, 2).ToString(), fNormal, 0);
                    // col 10
                    CommonPrinting.DrawGridDataItem(table, details[i].Price.ToString(), fNormal, 0);
                }
            }

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }
    }

    #endregion -- Order Printing --

    #region -- Yarn Order Printing --

    public static class YarnOrderPrinting
    {
        public static void AddOrderInfoToPdf(Document pdfFile, YarnOrder order, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Order Informations", fBold, 0, 2, 2f);
            // row 0
            CommonPrinting.DrawNormalItemInfo(table, "Customer Order No.", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.BelongToOrder.Id.ToString(), fBold, 0, 0, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Yarn Order No.", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Id.ToString(), fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Order Date", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.OrderDate.ToShortDateString(), fBold, 0, 0, 2f);
            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Method Of Payment", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.PaymentMethod.PaymentMethodName, fBold, 0, 0, 2f);
            // row 4
            CommonPrinting.DrawNormalItemInfo(table, "Method Of Delivery", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.DeliveryMethod.DeliveryMethodName, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddSupplierInfoToPdf(Document pdfFile, Supplier supplier, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Supplier Informations", fBold, 0, 2, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Name", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, supplier.SupplierName, fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Address", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, supplier.Address, fBold, 0, 0, 2f);
            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Phone", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, supplier.Phone, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddConditionInfoToPdf(Document pdfFile, YarnOrder order, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Order Conditions", fBold, 0, 2, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Dilivery Date", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.DeliveryDate.ToShortDateString(), fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Payment Condition", fNormal, 0, 0, 2f);
            string dataTemp = string.Empty;
            if (!order.IsDeliveredBefore && order.NumberOfDateExtensionDelivery == 0)
            {
                dataTemp = string.Empty;
            }
            else if (!order.IsDeliveredBefore && order.NumberOfDateExtensionDelivery != 0)
            {
                dataTemp = "After delivery " + order.NumberOfDateExtensionDelivery.ToString() + " day(s)";
            }
            else if (order.IsDeliveredBefore)
            {
                dataTemp = "Before delivery";
            }
            CommonPrinting.DrawNormalItemInfo(table, dataTemp, fBold, 0, 0, 2f);

            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Delivery address", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.DeliveryAddress, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddOrderDetailToPdf(Document pdfFile, IList<YarnOrderDetail> details, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(7);
            float[] widths = { 5f, 10f, 10f, 10f, 10f, 10f, 10f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Order Detail Informations", fBold, 0, 10, 2f);

            // row  header

            // col 1
            CommonPrinting.DrawGridHeaderItem(table, "No.", fBold);
            // col 2
            CommonPrinting.DrawGridHeaderItem(table, "Quantity Of Box", fBold);
            // col 3
            CommonPrinting.DrawGridHeaderItem(table, "Weight(Kg.)", fBold);
            // col 4
            CommonPrinting.DrawGridHeaderItem(table, "Composition", fBold);
            // col 5
            CommonPrinting.DrawGridHeaderItem(table, "Price", fBold);
            // col 6
            CommonPrinting.DrawGridHeaderItem(table, "Total Quantity", fBold);
            // col 7
            CommonPrinting.DrawGridHeaderItem(table, "Amount", fBold);

            // row data
            if (details != null && details.Count > 0)
            {
                for (int i = 0; i < details.Count; i++)
                {
                    // col 1
                    CommonPrinting.DrawGridDataItem(table, i + 1 + "", fNormal, 1);
                    // col 2
                    CommonPrinting.DrawGridDataItem(table, details[i].QuantityOfBox.ToString(), fNormal, 0);
                    // col 3
                    CommonPrinting.DrawGridDataItem(table, details[i].Weigth.ToString(), fNormal, 0);
                    // col 4
                    CommonPrinting.DrawGridDataItem(table, details[i].Composition.CompostionName, fNormal, 0);
                    // col 5
                    CommonPrinting.DrawGridDataItem(table, details[i].Price.ToString(), fNormal, 0);
                    // col 6
                    double totalQuantity = details[i].QuantityOfBox * details[i].Weigth;
                    CommonPrinting.DrawGridDataItem(table, totalQuantity.ToString(), fNormal, 0);
                    // col 7
                    double amount = totalQuantity * details[i].Price;
                    CommonPrinting.DrawGridDataItem(table, amount.ToString(), fNormal, 0);
                }
            }

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

    }

    #endregion -- Yarn Order Printing --

    #region -- Knitting Order --

    public static class KnittingOrderPrinting
    {
        public static void AddDemoInfoToPdf(Document pdfFile, KnittingOrder order, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Demo Informations", fBold, 0, 2, 2f);
            // row 0
            CommonPrinting.DrawNormalItemInfo(table, "Knitting Order No.", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.BelongToKnittingOrderId.ToString(), fBold, 0, 0, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Demo No.", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Id.ToString(), fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Order Date", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.OrderDate.ToShortDateString(), fBold, 0, 0, 2f);
            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Delivery Address", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.DeliveryAddress, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddOrderInfoToPdf(Document pdfFile, KnittingOrder order, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Order Informations", fBold, 0, 2, 2f);
            // row 0
            CommonPrinting.DrawNormalItemInfo(table, "Customer Order No.", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.BelongToOrder.Id.ToString(), fBold, 0, 0, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Knitting Order No.", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Id.ToString(), fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Order Date", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.OrderDate.ToShortDateString(), fBold, 0, 0, 2f);
            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Delivery Address", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.DeliveryAddress, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddSupplierInfoToPdf(Document pdfFile, Supplier supplier, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Supplier Informations", fBold, 0, 2, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Name", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, supplier.SupplierName, fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Address", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, supplier.Address, fBold, 0, 0, 2f);
            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Phone", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, supplier.Phone, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddTechnicalParametersToPdf(Document pdfFile, KnittingOrder order, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Pattern's Technical Parameters", fBold, 0, 2, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Fabric Type", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.FabricType.FabricTypeName, fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Composition", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Composition.CompostionName, fBold, 0, 0, 2f);

            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Length Of Yarn", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.LenghtOfYarnPer100Needles.ToString(), fBold, 0, 0, 2f);

            // row 4
            CommonPrinting.DrawNormalItemInfo(table, "Whale / Course", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.WhaleCourse.ToString(), fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddEstimatedKnittingMachinesToPdf(Document pdfFile, KnittingOrder order, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Estimated Knitting Machines", fBold, 0, 2, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Knitting Machine", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.KnittingMachine, fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Gauge", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Gauge, fBold, 0, 0, 2f);

            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Diameter", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Diameter, fBold, 0, 0, 2f);

            // row 4
            CommonPrinting.DrawNormalItemInfo(table, "Whale / Course", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.FabricWeight.ToString(), fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddOrderDetailToPdf(Document pdfFile, IList<KnittingOrderDetail> details, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(6);
            float[] widths = { 5f, 10f, 10f, 10f, 10f, 10f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Order Detail Informations", fBold, 0, 10, 2f);

            // row  header

            // col 1
            CommonPrinting.DrawGridHeaderItem(table, "No.", fBold);
            // col 2
            CommonPrinting.DrawGridHeaderItem(table, "Weight(Kg.)", fBold);
            // col 3
            CommonPrinting.DrawGridHeaderItem(table, "Length(Mt.)", fBold);
            // col 4
            CommonPrinting.DrawGridHeaderItem(table, "Composition", fBold);
            // col 5
            CommonPrinting.DrawGridHeaderItem(table, "Note On The Roll", fBold);
            // col 6
            CommonPrinting.DrawGridHeaderItem(table, "Price", fBold);

            // row data
            if (details != null && details.Count > 0)
            {
                for (int i = 0; i < details.Count; i++)
                {
                    // col 1
                    CommonPrinting.DrawGridDataItem(table, i + 1 + "", fNormal, 1);
                    // col 2
                    CommonPrinting.DrawGridDataItem(table, details[i].Weight.ToString(), fNormal, 0);
                    // col 3
                    CommonPrinting.DrawGridDataItem(table, details[i].Length.ToString(), fNormal, 0);
                    // col 4
                    CommonPrinting.DrawGridDataItem(table, details[i].Composition.CompostionName, fNormal, 0);
                    // col 5
                    CommonPrinting.DrawGridDataItem(table, details[i].Note, fNormal, 0);
                    // col 6
                    CommonPrinting.DrawGridDataItem(table, details[i].Price.ToString(), fNormal, 0);
                }
            }

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }
    }
    #endregion -- Knitting Order --

    #region -- Dye Order --

    public static class DyeOrderPrinting
    {
        public static void AddOrderInfoToPdf(Document pdfFile, DyeOrder order, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Order Informations", fBold, 0, 2, 2f);
            // row 0
            CommonPrinting.DrawNormalItemInfo(table, "Customer Order No.", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.BelongToOrder.Id.ToString(), fBold, 0, 0, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Dye Order No.", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Id.ToString(), fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Order Date", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.OrderDate.ToShortDateString(), fBold, 0, 0, 2f);
            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Delivery Address", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.DeliveryAddress, fBold, 0, 0, 2f);
            // row 4
            CommonPrinting.DrawNormalItemInfo(table, "Dye Instruction", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.DyeInstruction, fBold, 0, 0, 2f);

            // row 5
            CommonPrinting.DrawNormalItemInfo(table, "Article", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Article, fBold, 0, 0, 2f);

            // row 6
            CommonPrinting.DrawNormalItemInfo(table, "Composition", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Composition.CompostionName, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddSupplierInfoToPdf(Document pdfFile, Supplier supplier, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Supplier Informations", fBold, 0, 2, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Name", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, supplier.SupplierName, fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Address", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, supplier.Address, fBold, 0, 0, 2f);
            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Phone", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, supplier.Phone, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddAttributeToPdf(Document pdfFile, DyeOrder order, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Attribute", fBold, 0, 2, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Width", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Width.ToString(), fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Colour", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Color, fBold, 0, 0, 2f);
            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Mt", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Mt.ToString(), fBold, 0, 0, 2f);
            // row 4
            CommonPrinting.DrawNormalItemInfo(table, "GMS", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.GMS, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddOrderDetailToPdf(Document pdfFile, IList<DyeOrderDetail> details, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(4);
            float[] widths = { 5f, 10f, 10f, 10f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Order Detail Informations", fBold, 0, 10, 2f);

            // row  header

            // col 1
            CommonPrinting.DrawGridHeaderItem(table, "No.", fBold);
            // col 2
            CommonPrinting.DrawGridHeaderItem(table, "Weight(Kg.)", fBold);
            // col 3
            CommonPrinting.DrawGridHeaderItem(table, "Length(Mt.)", fBold);
            // col 4
            CommonPrinting.DrawGridHeaderItem(table, "Note On The Roll", fBold);

            // row data
            if (details != null && details.Count > 0)
            {
                for (int i = 0; i < details.Count; i++)
                {
                    // col 1
                    CommonPrinting.DrawGridDataItem(table, i + 1 + "", fNormal, 1);
                    // col 2
                    CommonPrinting.DrawGridDataItem(table, details[i].Weight.ToString(), fNormal, 0);
                    // col 3
                    CommonPrinting.DrawGridDataItem(table, details[i].Length.ToString(), fNormal, 0);
                    // col 4
                    string note = string.Empty;
                    if (details[i].IsCompact)
                    {
                        if (!string.IsNullOrEmpty(note))
                        {
                            note += ", ";
                        }
                        note += "Compact";
                    }
                    if (details[i].IsCuttingGomming)
                    {
                        if (!string.IsNullOrEmpty(note))
                        {
                            note += ", ";
                        }
                        note += "Cutting Gomming";
                    }
                    if (details[i].IsEnzim)
                    {
                        if (!string.IsNullOrEmpty(note))
                        {
                            note += ", ";
                        }
                        note += "Enzim";
                    }
                    if (details[i].IsResine)
                    {
                        if (!string.IsNullOrEmpty(note))
                        {
                            note += ", ";
                        }
                        note += "Resine";
                    }
                    if (details[i].IsRolling)
                    {
                        if (!string.IsNullOrEmpty(note))
                        {
                            note += ", ";
                        }
                        note += "Rolling";
                    }
                    if (details[i].IsSilicon)
                    {
                        if (!string.IsNullOrEmpty(note))
                        {
                            note += ", ";
                        }
                        note += "Silicon";
                    }
                    if (!string.IsNullOrEmpty(details[i].SpecialFinishing))
                    {
                        if (!string.IsNullOrEmpty(note))
                        {
                            note += ", ";
                        }
                        note += details[i].SpecialFinishing;
                    }

                    CommonPrinting.DrawGridDataItem(table, note, fNormal, 0);

                }
            }

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

    }

    #endregion -- Dye Order --

    #region -- Delivery --

    public static class DeliveryPrinting
    {
        public static void AddOrderInfoToPdf(Document pdfFile, Delivery order, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Delivery Informations", fBold, 0, 2, 2f);
            // row 0
            CommonPrinting.DrawNormalItemInfo(table, "Customer Order No.", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.BelongToOrder.Id.ToString(), fBold, 0, 0, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Delivery No.", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.Id.ToString(), fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Order Date", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.BelongToOrder.OrderDate.ToShortDateString(), fBold, 0, 0, 2f);
            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Delivery Date", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.DeliveryDate.ToShortDateString(), fBold, 0, 0, 2f);
            // row 4
            CommonPrinting.DrawNormalItemInfo(table, "Delivery Address", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.DeliveryAddress, fBold, 0, 0, 2f);
            // row 5
            CommonPrinting.DrawNormalItemInfo(table, "Method Of Delivery", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, order.BelongToOrder.DeliveryMethod.DeliveryMethodName, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddCustomerInfoToPdf(Document pdfFile, Customer customer, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(2);
            float[] widths = { 12f, 30f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Customer Informations", fBold, 0, 2, 2f);
            // row 1
            CommonPrinting.DrawNormalItemInfo(table, "Name", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, customer.CustomerName, fBold, 0, 0, 2f);
            // row 2
            CommonPrinting.DrawNormalItemInfo(table, "Address", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, customer.Address, fBold, 0, 0, 2f);
            // row 3
            CommonPrinting.DrawNormalItemInfo(table, "Phone", fNormal, 0, 0, 2f);
            CommonPrinting.DrawNormalItemInfo(table, customer.PhoneNumber, fBold, 0, 0, 2f);

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }

        public static void AddOrderDetailToPdf(Document pdfFile, IList<DeliveryDetail> details, Font fNormal, Font fBold)
        {
            PdfPTable table = new PdfPTable(8);
            float[] widths = { 5f, 10f, 10f, 10f, 10f, 10f, 10f, 10f };
            table.SetTotalWidth(widths);

            // row title
            CommonPrinting.DrawNormalItemInfo(table, "Delivery Detail Informations", fBold, 0, 10, 2f);

            // row  header

            // col 1
            CommonPrinting.DrawGridHeaderItem(table, "No.", fBold);
            // col 2
            CommonPrinting.DrawGridHeaderItem(table, "Fabric Type", fBold);
            // col 3
            CommonPrinting.DrawGridHeaderItem(table, "Colour", fBold);
            // col 4
            CommonPrinting.DrawGridHeaderItem(table, "Composition", fBold);
            // col 5
            CommonPrinting.DrawGridHeaderItem(table, "Qtt.(Mt)", fBold);
            // col 6
            CommonPrinting.DrawGridHeaderItem(table, "Qtt.(Kg)", fBold);
            // col 7
            CommonPrinting.DrawGridHeaderItem(table, "Cuttable Width", fBold);
            // col 8
            CommonPrinting.DrawGridHeaderItem(table, "Weight", fBold);

            // row data
            if (details != null && details.Count > 0)
            {
                for (int i = 0; i < details.Count; i++)
                {
                    // col 1
                    CommonPrinting.DrawGridDataItem(table, i + 1 + "", fNormal, 1);
                    // col 2
                    CommonPrinting.DrawGridDataItem(table, details[i].ReferenceToOrderDetail.FabricType.FabricTypeName, fNormal, 0);
                    // col 3
                    CommonPrinting.DrawGridDataItem(table, details[i].ReferenceToOrderDetail.Color, fNormal, 0);
                    // col 4
                    CommonPrinting.DrawGridDataItem(table, details[i].ReferenceToOrderDetail.Composition.CompostionName, fNormal, 0);
                    // col 5
                    CommonPrinting.DrawGridDataItem(table, details[i].MtQuantity.ToString(), fNormal, 0);
                    // col 6
                    CommonPrinting.DrawGridDataItem(table, details[i].KgQuantity.ToString(), fNormal, 0);
                    // col 7
                    CommonPrinting.DrawGridDataItem(table, details[i].ReferenceToOrderDetail.CuttableWidth.ToString(), fNormal, 0);
                    // col 8
                    CommonPrinting.DrawGridDataItem(table, details[i].ReferenceToOrderDetail.Weight.ToString(), fNormal, 0);
                }
            }

            table.SpacingAfter = 10f;
            pdfFile.Add(table);
        }
    }

    #endregion -- Delivery --
}
